//
//  FFRecvRecordCell.m
//  LLWallet
//
//  Created by tt on 2020/12/18.
//

#import "FFRecvRecordCell.h"

@implementation FFRecvRecordModel

- (Class)cell {
    return FFRecvRecordCell.class;
}

@end

@interface FFRecvRecordCell ()

@property(nonatomic,strong) UIImageView *avatarImgView;
@property(nonatomic,strong) UILabel *nameLbl;
@property(nonatomic,strong) UILabel *timeLbl;
@property(nonatomic,strong) UILabel *amountLbl;

@end

@implementation FFRecvRecordCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 60.0f);
}

- (void)setupUI {
    [super setupUI];
    
    [self addSubview:self.avatarImgView];
    [self addSubview:self.nameLbl];
    [self addSubview:self.timeLbl];
    [self addSubview:self.amountLbl];
}

- (void)refresh:(FFRecvRecordModel *)model {
    [super refresh:model];
    
    [self.avatarImgView setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[WKApp shared].config.defaultAvatar];
    self.nameLbl.text = model.name;
    [self.nameLbl sizeToFit];
    
    self.timeLbl.text = model.time;
    [self.timeLbl sizeToFit];
    
    self.amountLbl.text = [NSString stringWithFormat:@"¥%@",[WKMoneyUtil penny2Yuan:@(model.amount)]];
    [self.amountLbl sizeToFit];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.avatarImgView.lim_left = 15.0f;
    self.avatarImgView.lim_centerY_parent = self.contentView;
    
    CGFloat nameAndTimeSpace = 2.0f;
    CGFloat contentWidth = self.nameLbl.lim_height + nameAndTimeSpace + self.timeLbl.lim_height;
    self.nameLbl.lim_top = self.contentView.lim_height/2.0f - contentWidth/2.0f;
    self.nameLbl.lim_left = self.avatarImgView.lim_right + 10.0f;
    
    self.timeLbl.lim_top = self.nameLbl.lim_bottom + nameAndTimeSpace;
    self.timeLbl.lim_left = self.nameLbl.lim_left;
    
    self.amountLbl.lim_centerY_parent = self.contentView;
    self.amountLbl.lim_left = self.contentView.lim_width - self.amountLbl.lim_width - 15.0f;
    
}

- (UIImageView *)avatarImgView {
    if(!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 48.0f, 48.0f)];
        _avatarImgView.layer.masksToBounds = YES;
        _avatarImgView.layer.cornerRadius = _avatarImgView.lim_height/2.0f;
    }
    return _avatarImgView;
}

- (UILabel *)nameLbl {
    if(!_nameLbl) {
        _nameLbl = [[UILabel alloc] init];
        _nameLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
        _nameLbl.textColor = [WKApp shared].config.defaultTextColor;
    }
    return _nameLbl;
}

- (UILabel *)timeLbl {
    if(!_timeLbl) {
        _timeLbl = [[UILabel alloc] init];
        _timeLbl.font = [[WKApp shared].config appFontOfSize:13.0f];
        _timeLbl.textColor = [WKApp shared].config.tipColor;
    }
    return _timeLbl;
}

- (UILabel *)amountLbl {
    if(!_amountLbl) {
        _amountLbl = [[UILabel alloc] init];
        _amountLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
    }
    return _amountLbl;
}

@end
